<?php
/**
 * Created by PhpStorm.
 * User: u
 * Date: 2019/4/2
 * Time: 13:51
 */

namespace common\sources\write\praisekeywords;


use common\models\craftsman\PraiseKeywords;
use Yii;

class PraiseKeywordsAccess implements IPraiseKeywordsAccess
{
    public function addPraiseKeywords($data)
    {
        $connect  = Yii::$app->db;
        $queryBuilder = $connect->queryBuilder;
        $sql = $queryBuilder->batchInsert(PraiseKeywords::tableName(),['bus_id','task_commod_id','value_service_id','word','create_time'],$data);
        return $connect->createCommand($sql)->execute();
    }
    public function delPraisekeywords($value_service_id)
    {
        return PraiseKeywords::deleteAll(['value_service_id' => $value_service_id]);
    }

    public function ModifySelfKeyWords($id,$word) {
        $word = PraiseKeywords::findOne(['id' => $id]);
        if ($word) {
            $word->word = $word;
            if ($word->save()) {
                return true;
            }
        }
        return false;
    }


    //修改关键词
	public function editSelfKeyWords($id, $word) {
		$sql = 'UPDATE ' . PraiseKeywords::tableName() . ' SET word=:word ,update_time = :update_time WHERE id=:id ';
		return Yii::$app->db->createCommand($sql)
			->bindValues([
				':word'        => $word,
				':update_time' => time(),
				':id'          => $id
			])->execute();
	}

	// 修改关键词状态
	public function modifyPraisekeywords($data) {
		$sql = 'UPDATE ' . PraiseKeywords::tableName() . ' SET is_user = :is_user,update_time = :update_time WHERE id = :id ';
		return Yii::$app->db->createCommand($sql)
			->bindValues([
				':is_user'     => $data['is_user'],
				':update_time' => time(),
				':id'          => $data['id']
			])->execute();
	}
}